home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-25 | 75.8 KB | 2,271 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UIconEdit.cp
- // copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UICONEDIT__
- #include "UIconEdit.h"
- #endif
-
- // MacApp
-
- #ifndef __TOOLBOX__
- #include "Toolbox.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPRINTING__
- #include "UPrinting.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __PICKER__
- #include <Picker.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Constants
-
- const short kIconHBits = 32; // Number of horizontal bits in a bitmap.
- const short kIconVBits = 32; // Number of vertical bits in a bitmap.
-
- const short kIconSizeInBytes = 128; // Number of bytes in an bitmap.
- const short kIconSizeInLongs = 32; // Number of long words in a bitmap.
-
- // Resource identifiers
-
- const short kSeedIconId = 1000; // Id of the seed icon resource.
- const short kIconWindowId = 1000; // Id of the icon window 'view' resource.
- const short kIconEditViewId = 1001; // Id of the TIconEditView resource.
- const short kPencilCursorId = 1000; // Id of the pencil cursor resource.
-
- // Constants for TIconEditView
-
- const short kDefaultMagnification = 7; // Default icon magnification.
- const short kBorder = 5; // Border in which to inset drawing.
- const ResType kIconClipType = 'ICON'; // Our private clipboard data type.
-
- // Command Numbers
-
- const CommandNumber cZoomIn = 1000; // Zoom In menu command.
- const CommandNumber cZoomOut = 1001; // Zoom Out menu command.
- const CommandNumber cInvert = 1002; // Invert menu command.
- const CommandNumber cDrawCommand = 1003; // For drawing in the icon edit view.
- const CommandNumber cDrawPointsCommand = 1004; // set point apple event
- const CommandNumber cSetColor = 1005; // set a new document color
-
-
- short gSpecialDocCount; //Added by CKopala 8/24/96
- //========================================================================================
- // CLASS TIconEditApplication
- //========================================================================================
- #undef Inherited
- #define Inherited TApplication
-
- #pragma segment AInit
- MA_DEFINE_CLASS_M1(TIconEditApplication, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconEditApplication::IIconEditApplication:
- //----------------------------------------------------------------------------------------
- #pragma segment AInit
-
- void TIconEditApplication::IIconEditApplication()
- {
- this->IApplication(kFileType, kSignature);
-
- MA_REGISTER_CLASS(TIconEditView);
-
- gSpecialDocCount = 0; //Added by CKopala 8/24/96
- } // TIconEditApplication::IIconEditApplication
-
- //----------------------------------------------------------------------------------------
- // TIconEditApplication destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TIconEditApplication::~TIconEditApplication()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TIconEditApplication::DoMakeDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TDocument *TIconEditApplication::DoMakeDocument(CommandNumber /*itsCommandNumber*/,
- TFile* itsFile)
- {
- TIconDocument* anIconDocument;
- if (gSpecialDocCount >= 6) //Added by Ckopala 8/24/96
- Failure(memFullErr, 0); //Added by Ckopala 8/24/96
-
- anIconDocument = new TIconDocument; // Create a TIconDocument object.
- anIconDocument->IIconDocument(itsFile); // Initialize it.
-
- return anIconDocument; // Return a reference to the document.
- } // TIconEditApplication::DoMakeDocument
-
- //----------------------------------------------------------------------------------------
- // TIconEditApplication::GetContainedObject:
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
- MScriptableObject* TIconEditApplication::GetContainedObject(DescType desiredType,
- DescType selectionForm,const CAEDesc& selectionData)
- {
-
- MScriptableObject* result = NULL;
- TDocument* theDocument = NULL;
-
- if (desiredType == cDocument && selectionForm == formName)
- {
- //Note: MacApp 3.3.1 TApplication::GetContainedObject dose not work if a script
- //attempts to get a document that does not exist. In the case where there are
- //no open documents, the result is an access fault. Therefore, I'm using the
- //following substitute code.
- CStr255 theName;
- selectionData.GetString(theName);
- CNoGhostDocsIterator iter(this);
-
- for (TDocument* aDocument = iter.FirstDocument(); iter.More(); aDocument = iter.NextDocument())
- {
- if (aDocument != NULL)
- {
- CStr255 name = gEmptyString;
- aDocument -> GetTitle(name);
- if (name == theName)
- {
- theDocument = aDocument;
- result = theDocument;
- return result;
- }
- }
- }
- }
- else
- {
- result = Inherited::GetContainedObject(desiredType, selectionForm, selectionData);
- }
- return result;
- }
- //----------------------------------------------------------------------------------------
- // TIconEditApplication::MakeViewForAlienClipboard:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- TView* TIconEditApplication::MakeViewForAlienClipboard()
- {
- long offset;
-
- // Does the scrap contain my type?
- if (GetScrap(NULL, kIconClipType, &offset) > 0)
- {
- TIconDocument* clipDocument = NULL;
- TIconEditView* clipView = NULL;
-
- // Need a document to represent the data to be put on the clipboard.
- clipDocument = new TIconDocument;
- clipDocument->IIconDocument(NULL);
-
- FailInfo fi;
- Try(fi) // Install failure handler.
- {
- clipDocument->ReturnBitMap()->LoadFromScrap(); // Get 'ICON' data from scrap.
-
- clipView = new TIconEditView;
- clipView->IIconEditView(clipDocument, NULL, gZeroVPt, 1);
-
- fi.Success(); // Don't need failure handler
- // anymore.
- }
- else
- {
- clipDocument = (TIconDocument*)FreeIfObject(clipDocument); // Free
- // clipDocument
- fi.ReSignal();
- }
- return clipView; // Return view for Clipboard.
- }
- else
- return Inherited::MakeViewForAlienClipboard();
- } // TIconEditApplication::MakeViewForAlienClipboard
-
-
- //========================================================================================
- // CLASS TIconDocument
- //========================================================================================
- #undef Inherited
- #define Inherited TFileBasedDocument
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TIconDocument, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconDocument constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TIconDocument::TIconDocument()
- {
- fIconBitMap = NULL; // Set this to NULL so that if IDocument
- // fails, TIconDocument.Free works okay.
- fIconView = NULL;
- fColor = gRGBBlack; // init drawing color to black
-
- gSpecialDocCount++; //Added by CKopala 8/24/96
- } // TIconDocument::TIconDocument
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::IIconDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TIconDocument::IIconDocument(TFile* itsFile)
- {
- TIconBitMap* anIconBitMap;
-
- this->IFileBasedDocument(itsFile, // This document's file
- kSignature); // This document's scrap type
-
- FailInfo fi; // Install failure handler in case we
- Try(fi) // can't create the bit map object.
- {
- anIconBitMap = new TIconBitMap; // Allocate a new icon bitmap.
- anIconBitMap->IIconBitMap(); // Initialize it.
- fIconBitMap = anIconBitMap;
-
- fi.Success(); // Don't need failure handler anymore.
- }
- else
- {
- this->Free(); // Free me too!
- fi.ReSignal();
- }
- } // TIconDocument::IIconDocument
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment AClose
- TIconDocument::~TIconDocument()
- {
- fIconBitMap = (TIconBitMap*)FreeIfObject(fIconBitMap);// Dispose of the bitmap if
- // non-NULL.
- gSpecialDocCount--; //Added by CKopala 8/24/96
- } // TIconDocument::Free
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoInitialState: This method is called to set the document's data to the
- // "new" state, as when the user chooses to open a new document instead of an existing
- // one. We set the value of the document's icon bit map to that of a "seed" icon in our
- // resource file. That way we can the document's initial state simply by changing the
- // "seed" icon resource.
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TIconDocument::DoInitialState() // OVERRIDE
- {
- Handle seedIcon;
-
- seedIcon = GetIcon(kSeedIconId); // Get the seed icon resource
- if (seedIcon != NULL) // If we got the seed icon resource
- fIconBitMap->SetIconBitMap(seedIcon);
- #if qDebug
- else
- ProgramBreak("Unable to get the seed icon resource.");
- #endif
-
- } // TIconDocument::DoInitialState
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TIconDocument::DoMakeViews(Boolean forPrinting)// OVERRIDE
- {
- TWindow* aWindow;
- TIconEditView* iconView;
- TStdPrintHandler* aPrintHandler;
-
- if (forPrinting) // If for printing, only need the view.
- {
- iconView = (TIconEditView *)gViewServer->DoCreateViews(this, NULL, kIconEditViewId, gZeroVPt);//new
- FailNIL(iconView);
- }
- else
- { // Otherwise need view and window.
- FailNIL(aWindow = gViewServer->NewTemplateWindow(kIconWindowId, this));
- iconView = (TIconEditView*)(aWindow->FindSubView('ICON')); // Get reference to
- // the view.
- }
-
- fIconView = iconView;
-
- aPrintHandler = new TStdPrintHandler; // Create a print handler.
- aPrintHandler->IStdPrintHandler(this, // The document.
- iconView, // The view to be printed.
- !kSquareDots,
- kFixedSize, // Horzontal page size is fixed.
- kFixedSize); // Vertical page size is fixed.
- } // TIconDocument::DoMakeViews
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconDocument::DoMenuCommand (CommandNumber aCommandNumber)
- {
-
- switch (aCommandNumber)
- {
- case cInvert:
- TInvertCommand *anInvertCommand = new TInvertCommand;
- anInvertCommand->IInvertCommand(this);
- anInvertCommand->fUseAppleEvent = TRUE;
- PostCommand(anInvertCommand);
- break;
-
- case cZoomIn:
- TZoomInCommand * theZoomInCommand = new TZoomInCommand();
- theZoomInCommand->IZoomInCommand(this);
- theZoomInCommand->fUseAppleEvent = TRUE;
- this->PostCommand(theZoomInCommand);
- break;
-
- case cZoomOut:
- TZoomOutCommand * theZoomOutCommand = new TZoomOutCommand();
- theZoomOutCommand->IZoomOutCommand(this);
- theZoomOutCommand->fUseAppleEvent = TRUE;
- this->PostCommand(theZoomOutCommand);
- break;
-
- case cSetColor:
- {
- CRGBColor newColor;
- CStr255 thePrompt = "Pick a new color";
- if (GetColor(kBestSystemLocation, thePrompt, fColor, newColor))
- {
- if (TOSADispatcher::fgDispatcher->GetDefaultTarget()->IsRecordingOn())
- {
- TSetPropertyEvent *appleEvent = new TSetPropertyEvent;
- appleEvent->ISetPropertyEvent(gServerAddress, kAENoReply, this, pColor);
- CTempDesc theNewColor;
- theNewColor.PutRGBColor(newColor);
- appleEvent->WriteParameter(keyAEData, theNewColor);
- appleEvent->Send();
- }
- else
- {
- TSetColorCommand *aSetColorCommand = new TSetColorCommand();
- aSetColorCommand->ISetColorCommand(this, newColor);
- PostCommand(aSetColorCommand);
- }
- }
- }
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- } // TIconDocument::DoMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoScriptCommand (OVERRIDE)
- //----------------------------------------------------------------------------------------
-
- void TIconDocument::DoScriptCommand(CommandNumber aCommand,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- switch (aCommand)
- {
- case cInvert:
- {
- TInvertCommand *anInvertCommand = new TInvertCommand;
- anInvertCommand->IInvertCommand(this);
- PostCommand(anInvertCommand);
- }
- break;
-
- case cZoomIn:
- TZoomInCommand * theZoomInCommand = new TZoomInCommand();
- theZoomInCommand->IZoomInCommand(this);
- this->PostCommand(theZoomInCommand);
- break;
-
- case cZoomOut:
- TZoomOutCommand * theZoomOutCommand = new TZoomOutCommand();
- theZoomOutCommand->IZoomOutCommand(this);
- this->PostCommand(theZoomOutCommand);
- break;
-
- case cDrawPointsCommand:
- {
- TDrawPointsCommand *drawPointsCommand = new TDrawPointsCommand;
- drawPointsCommand->IDrawPointsCommand(this, message);
- PostCommand(drawPointsCommand);
- }
- break;
-
- default:
- Inherited::DoScriptCommand(aCommand, message, reply);
- break;
- }
- } // TIconDocument::DoScriptCommand
-
- TIconEditView* TIconDocument::GetIconView()
- {
- return fIconView;
- }
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoNeedDiskSpace:
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TIconDocument::DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes)//new
- {
- Inherited::DoNeedDiskSpace( itsFile,
- dataForkBytes,// In case parent class saves data.
- rsrcForkBytes);
-
- dataForkBytes = dataForkBytes + // Add the size of the icon in bytes and
- kIconSizeInBytes + // the space taken up by the color information
- sizeof(CRGBColor); // …the number of bytes in the data fork.
- } // TIconDocument::DoNeedDiskSpace
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoRead:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TIconDocument::DoRead(TFile* itsFile,
- Boolean forPrinting)
- {
- Inherited::DoRead(itsFile, forPrinting); // In case parent class reads data.
-
- TFileStream* theFileStream = new TFileStream;
-
- theFileStream->IFileStream(itsFile);
- fIconBitMap->ReadFrom(theFileStream); // Read Data from the file system into
- // …the icon and handle any errors.
-
- theFileStream->ReadBytes(fColor, sizeof(CRGBColor)); // read the color from the stream
-
- theFileStream->Free();
- } // TIconDocument::DoRead
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconDocument::DoSetupMenus()
- {
- Inherited::DoSetupMenus(); // Set up inherited menus.
- Enable(cInvert, TRUE); // The icon can always be inverted.
- Enable(cSetColor, TRUE); // The color can always be set
- } // TIconDocument::DoSetupMenus
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::DoWrite:
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TIconDocument::DoWrite(TFile* itsFile,
- Boolean makingCopy)
- {
- Inherited::DoWrite(itsFile, makingCopy); // In case parent class writes data.
-
- TFileStream* theFileStream = new TFileStream;
-
- theFileStream->IFileStream(itsFile);
- fIconBitMap->WriteTo(theFileStream); // Write data the icon to the file
- // …and handle any errors.
-
- theFileStream->WriteBytes(&fColor, sizeof(CRGBColor));
-
- theFileStream->Free();
- } // TIconDocument::DoWrite
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::InvertIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDocument::InvertIcon()
- {
- fIconBitMap->Invert(); // Invert the bits of the icon.
- this->RedrawViews(); // Make sure all views get redrawn.
- } // TIconDocument::InvertIcon
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::ClearIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDocument::ClearIcon()
- {
- fIconBitMap->Clear(); // Clear the icon bits.
- this->RedrawViews(); // Make sure all views get redrawn.
- } // TIconDocument::ClearIcon
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::SetIcon:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDocument::SetIcon(TIconBitMap* newIcon)
- {
- if (fIconBitMap != newIcon)
- {
- fIconBitMap = (TIconBitMap *)FreeIfObject(fIconBitMap);
- fIconBitMap = newIcon; // Note this doesn't copy the icon.
- }
- this->RedrawViews(); // Make sure all views get redrawn.
-
- } // TIconDocument::SetIcon
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::ReturnBitMap:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- TIconBitMap* TIconDocument::ReturnBitMap()
- {
- return fIconBitMap;
- } // TIconDocument::ReturnBitMap
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::RedrawViews:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconDocument::RedrawViews()
- {
- fIconView->ForceRedraw();
- } // TIconDocument::RedrawViews
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::GetSetPropertyInfo: {OVERRIDE}
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconDocument::GetSetPropertyInfo( DescType whichProperty,
- CommandNumber& cmdNum,
- Boolean& canUndo,
- Boolean& causesChange,
- TCommandHandler* &theContext)
- {
- switch(whichProperty)
- {
- case pColor:
- cmdNum = cSetColor;
- canUndo = TRUE;
- causesChange = TRUE;
- theContext = this;
- break;
-
- default:
- Inherited::GetSetPropertyInfo(whichProperty, cmdNum, canUndo, causesChange, theContext);
- break;
- }
- } // TIconDocument::GetSetPropertyInfo
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::GetObjectProperty: {OVERRIDE}
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TIconDocument::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- Boolean hasProperty = TRUE;
-
- switch (whichProperty)
- {
- case pColor:
- thePropertyValue.PutRGBColor(fColor);
- break;
-
- default:
- hasProperty = Inherited::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
-
- }
-
- return hasProperty;
- }
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::SetObjectProperty: {OVERRIDE}
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconDocument::SetObjectProperty( const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- switch(whichProperty)
- {
- case pColor:
- thePropertyValue.GetRGBColor(fColor);
- this->RedrawViews();
- break;
-
- default:
- Inherited::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
-
-
-
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::GetIconColor: Return the color of the bit map.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- CRGBColor TIconDocument::GetIconColor()
- {
- return fColor;
- } // TIconDocument::GetIconColor
-
- //----------------------------------------------------------------------------------------
- // TIconDocument::SetIconColor: Set the color of the icon bitmap.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconDocument::SetIconColor(CRGBColor& newColor)
- {
- fColor = newColor;
- this->RedrawViews();
- } // TIconDocument::SetIconColor
-
- //========================================================================================
- // CLASS TIconEditView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TIconEditView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconEditView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TIconEditView::TIconEditView()
- {
- fMagnification = kDefaultMagnification;
- } // TIconEditView::TIconEditView
-
- //----------------------------------------------------------------------------------------
- // TIconEditView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TIconEditView::~TIconEditView()
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::IIconEditView:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TIconEditView::IIconEditView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- short itsMagnification)
- {
- this->IView(itsDocument, itsSuperView, itsLocation, gZeroVPt, sizeVariable, sizeVariable);
-
- fMagnification = itsMagnification;
- fIconDocument = (TIconDocument*)itsDocument;
- } // TIconEditView::IIconEditView
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TIconEditView::DoPostCreate(TDocument* itsDocument)
- {
- fIconDocument = (TIconDocument*)itsDocument;
- } // TIconEditView::DoPostCreate
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::CalcMinFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment ANonRes
-
- void TIconEditView::CalcMinFrame(VRect& minFrame)
- {
- minFrame = VRect ( 0,
- 0,
- kIconHBits * fMagnification + kBorder + kBorder,
- kIconVBits * fMagnification + kBorder + kBorder);
- } // TIconEditView::CalcMinFrame
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::ContainsClipType:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- Boolean TIconEditView::ContainsClipType(ResType aType)
- {
- return (aType == kIconClipType);
- } // TIconEditView::ContainsClipType
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconEditView::DoMenuCommand(CommandNumber aCommandNumber)
- {
- TIconEditCommand* anIconEditCommand;
- TIconPasteCommand* anIconPasteCommand;
-
- switch (aCommandNumber) // Decide if this command is ours…
- {
- case cCut:
- case cCopy:
- case cClear:
- { // Post a TIconEditCommand object.
- anIconEditCommand = new TIconEditCommand;
- anIconEditCommand->IIconEditCommand(aCommandNumber, this, fIconDocument);
- this->PostCommand(anIconEditCommand);
- return;
- }
-
- case cPaste:
- { // Post a TIconPasteCommand object.
- anIconPasteCommand = new TIconPasteCommand;
- anIconPasteCommand->IIconPasteCommand(this, fIconDocument);
- this->PostCommand(anIconPasteCommand);
- return;
- }
-
- default: // Otherwise, let someone else handle it.
- Inherited::DoMenuCommand(aCommandNumber);
- return;
- }
- } // TIconEditView::DoMenuCommand
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DoKeyEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconEditView::DoKeyEvent(TToolboxEvent* info)
- {
- TIconEditCommand* anIconEditCommand;
-
- if (info->fCharacter == chBackspace)
- {
- // Post a TIconEditCommand object.
- anIconEditCommand = new TIconEditCommand;
- anIconEditCommand->IIconEditCommand(cClear, this, fIconDocument); // Same as Clear menu command.
- this->PostCommand(anIconEditCommand);
- return;
- }
- Inherited::DoKeyEvent(info); // In case someone else wants it.
- } // TIconEditView::DoKeyEvent
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconEditView::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* /*event*/ ,
- CPoint /*hysteresis*/)
- {
- VPoint iconBit;
- TIconDrawCommand* anIconDrawCommand;
-
- if (this->PointToBit(theMouse, iconBit)) // If CPoint is within the icon
- {
- anIconDrawCommand = new TIconDrawCommand; // …then make a drawing command.
- anIconDrawCommand->IIconDrawCommand(this, fIconDocument, theMouse);
- this->PostCommand(anIconDrawCommand); // and Post it.
- return;
- }
- return; // …else take no action.
- } // TIconEditView::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DoSetCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconEditView::DoSetCursor(const VPoint& localPoint,
- RgnHandle cursorRegion)//new
- {
- VPoint iconBit;
- CursHandle pencilCursor;
-
- CTemporaryRegion outerRegion;
- CTemporaryRegion innerRegion;
-
- this->GetExtentRegion(outerRegion);
- CopyRgn(outerRegion,innerRegion);
- InsetRgn(innerRegion,kBorder,kBorder);
-
- if (this->PointToBit(localPoint, iconBit)) // If the cursor is not in the borders…
- {
- pencilCursor = GetCursor(this->GetCursorID()); // Attempt to get the pencil cursor.
- FailNILResource((Handle)pencilCursor);
- SetCursor(*pencilCursor); // Set the cursor on the screen.
- CopyRgn(innerRegion,cursorRegion);
- }
- else
- {
- SetCursor(&(qd.arrow)); // Set the cursor on the screen.
- DiffRgn(outerRegion,innerRegion,cursorRegion);
- }
- } // TIconEditView::DoSetCursor
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconEditView::DoSetupMenus()
- {
- Inherited::DoSetupMenus(); // Set up inherited menus.
-
- Enable(cZoomIn, TRUE); // Can always zoom in.
- Enable(cZoomOut, fMagnification > 1); // Can zoom out if not at smallest size.
- Enable(cSetColor, TRUE); // can always set the color
- Enable(cCut, TRUE); // Always enable the Cut command.
- Enable(cCopy, TRUE); // Always enable the Copy command.
- Enable(cClear, TRUE); // Always enable the Clear command.
- gClipboardMgr->CanPaste(kIconClipType); // This view can paste 'ICON' data.
- } // TIconEditView::DoSetupMenus
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconEditView::Draw (const VRect& /*area*/) //new
- {
- CRect drawingRect = CRect ( kBorder,
- kBorder,
- kBorder + (kIconHBits * fMagnification),
- kBorder + (kIconVBits * fMagnification));
- fIconDocument->ReturnBitMap()->Draw(drawingRect, fIconDocument->GetIconColor());
- } // TIconEditView::Draw
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::DrawBit:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconEditView::DrawBit ( VPoint theBit,
- Boolean turnBitOn,
- CRGBColor& drawingColor)
- {
- CRect theRect = CRect ( kBorder + ((short) theBit.h) * fMagnification,
- kBorder + ((short) theBit.v) * fMagnification,
- kBorder + ((short) (theBit.h + 1)) * fMagnification,
- kBorder + ((short) (theBit.v + 1)) * fMagnification);
- // Setup the bit's CRect the in edit view.
-
- if (turnBitOn)
- {
- if (qNeedsColorQD || HasColorQD())
- {
- CRGBColor oldColor;
-
- GetIfColor(oldColor);
- SetIfColor(drawingColor);
-
- PenNormal();
- PaintRect(theRect);
- SetIfColor(oldColor);
- }
- else
- FillRect(theRect, &qd.black);
- }
- else
- FillRect(theRect, &qd.white);
- } // TIconEditView::DrawBit
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::PointToBit: Converts the given mouse CPoint to an icon bit.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TIconEditView::PointToBit(const VPoint& thePoint,
- VPoint& iconBit)
- {
- VPoint aPoint = thePoint; // use a copy, since thePoint is a const
- aPoint.h = aPoint.h - kBorder; // Account for border in the edit view.
- aPoint.v = aPoint.v - kBorder;
-
- // If the mouse is within the edit view's icon…
- if ((aPoint.h >= 0) && (aPoint.h < kIconHBits * fMagnification) &&
- (aPoint.v >= 0) && (aPoint.v < kIconVBits * fMagnification))
- {
- iconBit.h = aPoint.h / fMagnification; // Convert from edit view CPoint
- iconBit.v = aPoint.v / fMagnification; // …to icon bit.
- return TRUE;
- }
-
- return FALSE; // CPoint is not within the icon.
- } // TIconEditView::PointToBit
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::GetMagnification:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- short TIconEditView::GetMagnification()
- {
- return fMagnification; // SGet the new magnification.
- } // TIconEditView::GetMagnification
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::SetMagnification:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconEditView::SetMagnification(short magnification)
- {
- fMagnification = (short) Max(1, magnification); // Set the new magnification.
- this->AdjustFrame(); // Magnification affects the view's size.
- this->ForceRedraw(); // Force the view to be entirely redrawn.
- } // TIconEditView::SetMagnification
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditView::WriteToDeskScrap:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TIconEditView::WriteToDeskScrap()
- {
- fIconDocument->ReturnBitMap()->WriteToScrap(); // Write the icon data to the clipboard.
- Inherited::WriteToDeskScrap(); // Write 'PICT' data to the desk scrap.
- } // TIconEditView::WriteToDeskScrap
-
-
-
- //========================================================================================
- // CLASS TDrawLineAppleEvent
- //========================================================================================
- #undef Inherited
- #define Inherited TAppleEvent
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TDrawPointsAppleEvent, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDrawLineAppleEvent constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TDrawPointsAppleEvent::TDrawPointsAppleEvent()
- {
- // nothing to do
- } // TDrawPointsAppleEvent::TDrawPointsAppleEvent
-
- //----------------------------------------------------------------------------------------
- // TDrawPointsAppleEvent destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TDrawPointsAppleEvent::~TDrawPointsAppleEvent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TDrawPointsAppleEvent::IDrawPointsAppleEvent
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TDrawPointsAppleEvent::IDrawPointsAppleEvent( MScriptableObject *itsDirectObject,
- TIconBitMap *iconBitMapModel,
- const Boolean turnBitsOn)
- {
- CTempDesc directObjectDesc;
- VPoint iconBit;
- CPoint qdPoint;
-
-
- this->IAppleEvent(kAEIconEditClass, kAEDrawPoints, gServerAddress, kAENoReply+kAEDontExecute);
- itsDirectObject->MakeObjectSpecifier(directObjectDesc, formUniqueID);
- this->WriteParameter(keyDirectObject, directObjectDesc);
-
- TDynamicArray *pointArray = new TDynamicArray; // create an array to store a list of points
- pointArray->IDynamicArray(1, sizeof(CPoint));
-
- // add the points set in the model to the dynamic array
- for (short vCoord = 0; vCoord < kIconVBits; ++vCoord)
- {
- iconBit.v = vCoord;
- for (short hCoord = 0; hCoord < kIconHBits; ++hCoord)
- {
- iconBit.h = hCoord;
- if (iconBitMapModel->GetBit(iconBit))
- {
- qdPoint = iconBit.ToPoint(); // convert the iconBit to a CPoint
- pointArray->InsertElementsBefore(pointArray->GetSize() + 1, &qdPoint, 1);
- }
- }
- }
-
- // write the point list to the apple event parameter list
- this->WritePtrList(keyPointList, typeQDPoint, pointArray);
-
- pointArray = (TDynamicArray *)FreeIfObject(pointArray);
-
- // if turning the points off, add an optional parameter
- if (!turnBitsOn)
- this->WriteBoolean(keyErasePoints, TRUE);
- } // TDrawPointsAppleEvent::IDrawPointsAppleEvent
-
- //========================================================================================
- // CLASS TInvertCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TInvertCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TInvertCommand::TInvertCommand()
- {
- fIconDocument = NULL;
- } // TInvertCommand::TInvertCommand
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TInvertCommand::~TInvertCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand::IInvertCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TInvertCommand::IInvertCommand(TIconDocument* itsIconDocument)
- {
- this->ICommand(cInvert, // Initialize the inherited data…
- itsIconDocument,
- kCanUndo,
- kCausesChange,
- itsIconDocument); // …no view or scroller to track.
- fIconDocument = itsIconDocument; // Save a reference to the icon document.
- } // TInvertCommand::IInvertCommand
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand::MakeAppleEvent
- //----------------------------------------------------------------------------------------
- TAppleEvent * TInvertCommand::MakeAppleEvent()
- {
- CTempDesc directObjectDesc;
- TAppleEvent * theInvertEvent = new TAppleEvent;
-
- theInvertEvent->IAppleEvent(kAEIconEditClass, kAEInvertID,gServerAddress, kAENoReply);
- fIconDocument->MakeObjectSpecifier(directObjectDesc, fIconDocument->GetSpecifierForm()); // create a descriptor
- theInvertEvent->WriteParameter(keyDirectObject, directObjectDesc);
-
- return theInvertEvent;
- }
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInvertCommand::DoIt()
- {
- fIconDocument->InvertIcon(); // Invert the document's icon bitmap.
- } // TInvertCommand::DoIt
-
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInvertCommand::UndoIt()
- {
- fIconDocument->InvertIcon(); // Uninvert the document's icon bitmap.
- } // TInvertCommand::UndoIt
-
-
- //----------------------------------------------------------------------------------------
- // TInvertCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TInvertCommand::RedoIt()
- {
- fIconDocument->InvertIcon(); // Reinvert the document's icon bitmap.
- } // TInvertCommand::RedoIt
-
- //========================================================================================
- // CLASS TDrawPointsCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TDrawPointsCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSetPointsCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TDrawPointsCommand::TDrawPointsCommand()
- {
- fSavedBitMap = NULL;
- fIconDocument = NULL;
- fErasePoints = FALSE; // by default, turn bits on
- } // TDrawPointsCommand::TDrawPointsCommand
-
- //----------------------------------------------------------------------------------------
- // TDrawPointsCommand::IDrawPointsCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TDrawPointsCommand::IDrawPointsCommand(TIconDocument *itsIconDocument,
- TAppleEvent *theAppleEvent)
- {
- fIconDocument = itsIconDocument;
-
- this->ICommand(cDrawPointsCommand, // Initialize the inherited data…
- itsIconDocument,
- kCanUndo,
- kCausesChange,
- itsIconDocument);
-
- // read the required pointlist parameter
- fPointList = new TDynamicArray;
- fPointList->IDynamicArray(1, sizeof(CPoint));
-
- theAppleEvent->ReadPtrList(keyPointList, typeQDPoint, fPointList);
-
- // read the optional erasePoints parameter
- if (theAppleEvent->HasParameter(keyErasePoints))
- fErasePoints = theAppleEvent->ReadBoolean(keyErasePoints);
- } // TDrawLineCommand::IDrawLineCommand
-
-
-
- //----------------------------------------------------------------------------------------
- // TDrawPointsCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TDrawPointsCommand::DoIt()
- {
- TIconBitMap *targetBitMap = fIconDocument->ReturnBitMap();
- fSavedBitMap = targetBitMap->Copy(); // save the current bitmap
-
- // draw the points listed in the pointlist
- CArrayIterator iter(fPointList);
- CPoint aPoint;
- VPoint iconBit;
-
- for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
- {
- fPointList->GetElementsAt(i, (Point *)aPoint, 1);
- iconBit.h = aPoint.h;
- iconBit.v = aPoint.v;
- targetBitMap->SetBit(iconBit, !fErasePoints); // set the bit in the bitmap
- }
-
- fIconDocument->SetIcon(targetBitMap); // this will cause a redraw
- // free the point list…it won't be used again
- fPointList = (TDynamicArray *)FreeIfObject(fPointList);
-
- } // TDrawPointsCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TDrawPointsCommand::UndoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TDrawPointsCommand::UndoIt()
- {
- TIconBitMap *tempBitMap = fIconDocument->ReturnBitMap()->Copy(); // save a local copy
- fIconDocument->SetIcon(fSavedBitMap);
- fSavedBitMap = tempBitMap;
- //fIconDocument->SetIcon(fOriginalBitMap);
- } // TDrawPointsCommand::UndoIt
-
-
- //----------------------------------------------------------------------------------------
- // TDrawPointsCommand::RedoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TDrawPointsCommand::RedoIt()
- {
- TIconBitMap *tempBitMap = fIconDocument->ReturnBitMap()->Copy(); // save a local copy
- fIconDocument->SetIcon(fSavedBitMap);
- fSavedBitMap = tempBitMap;
- } // TDrawPointsCommand::RedoIt
-
-
- //----------------------------------------------------------------------------------------
- // TDrawLineCommand::Free
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- TDrawPointsCommand::~TDrawPointsCommand()
- {
- if (fCommandDone)
- fSavedBitMap = (TIconBitMap *)FreeIfObject(fSavedBitMap);
-
- fPointList = (TDynamicArray *)FreeIfObject(fPointList);
- } // TDrawPointsCommand::Free
-
- //========================================================================================
- // CLASS TSetColorCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TSetColorCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSetColorCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TSetColorCommand::TSetColorCommand()
- {
- } // TSetColorCommand::TSetColorCommand
-
- //----------------------------------------------------------------------------------------
- // TSetColorCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSetColorCommand::~TSetColorCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSetColorCommand::ISetColorCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TSetColorCommand::ISetColorCommand(TIconDocument *itsDocument,
- CRGBColor& newColor)
- {
- this->ICommand( cSetColor, // Initialize the command…
- itsDocument, // Associate it with a document.
- kCanUndo,
- kCausesChange,
- itsDocument);
- fNewColor = newColor;
- fOldColor = itsDocument->GetIconColor();
- } // TPickColorCommand::IPickColorCommand
-
- //----------------------------------------------------------------------------------------
- // TSetColorCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TSetColorCommand::DoIt()
- {
- ((TIconDocument *)fContext)->SetIconColor(fNewColor);
- } // TSetColorCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TSetColorCommand::UndoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TSetColorCommand::UndoIt()
- {
- ((TIconDocument *)fContext)->SetIconColor(fOldColor);
- } // TSetColorCommand::UndoIt
-
- //----------------------------------------------------------------------------------------
- // TSetColorCommand::RedoIt
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TSetColorCommand::RedoIt()
- {
- ((TIconDocument *)fContext)->SetIconColor(fNewColor);
- } // TSetColorCommand::RedoIt
-
-
- //========================================================================================
- // CLASS TIconDrawCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TTracker
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TIconDrawCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TIconDrawCommand::TIconDrawCommand()
- {
- fIconDocument = NULL;
- fIconEditView = NULL;
- fIconBitMap = NULL;
- fOriginalIcon = NULL;
- fTurnBitsOn = TRUE;
- fIconBitMapModel = NULL;
- } // TIconDrawCommand::TIconDrawCommand
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::IIconDrawCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconDrawCommand::IIconDrawCommand(TIconEditView* itsIconEditView,
- TIconDocument* itsIconDocument,
- VPoint& theMouse)
- {
- this->ITracker( cDrawCommand, // Initialize the command…
- itsIconDocument, // Its context
- kCanUndo,
- kCausesChange,
- itsIconDocument, // Associate it with a notifying object.
- itsIconEditView, // Associate it with a view.
- itsIconEditView->GetScroller(TRUE), // Associate it with a scroller
- theMouse);
- fConstrainsMouse = TRUE; // Want TrackConstrain called.
-
- fIconEditView = itsIconEditView; // Set some convenience fields…
- fIconDocument = itsIconDocument;
- fIconBitMap = fIconDocument->ReturnBitMap(); // Get reference to icon being drawn.
- fIconBitMapModel = new TIconBitMap; // create a model for the bits being set
- fIconBitMapModel->IIconBitMap();
- fIconBitMapModel->Clear();
-
- fColor = fIconDocument->GetIconColor(); // store the drawing color
- } // TIconDrawCommand::IIconDrawCommand
-
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- TIconDrawCommand::~TIconDrawCommand()
- {
- if (fCommandDone) // If the command is done…
- fOriginalIcon = (TIconBitMap*)FreeIfObject(fOriginalIcon); // …dispose of original icon.
- else // Else if command is undone…
- fIconBitMap = (TIconBitMap*)FreeIfObject(fIconBitMap); // …dispose of icon that was drawn
-
- fIconBitMapModel = (TIconBitMap*)FreeIfObject(fIconBitMapModel); // free the bitmap model
- } // TIconDrawCommand::Free
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::TrackConstrain:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDrawCommand::TrackConstrain(TrackPhase /*aTrackPhase*/,
- const VPoint& /*anchorPoint*/ ,
- const VPoint& /*previousPoint*/ ,
- VPoint& nextPoint,
- Boolean /*mouseDidMove*/)
- {
- // This is on several lines so that Max can be "inlined"
- VCoordinate h = Min(nextPoint.h, fIconEditView->fSize.h - kBorder - 1);
- VCoordinate v = Min(nextPoint.v, fIconEditView->fSize.v - kBorder - 1);
- h = Max(h, (long) kBorder);
- v = Max(v, (long) kBorder);
- nextPoint = VPoint(h, v);
- } // TIconDrawCommand::TrackConstrain
-
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::TrackFeedback:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDrawCommand::TrackFeedback(TrackPhase /*aTrackPhase*/,
- const VPoint& /*anchorPoint*/,
- const VPoint& /*previousPoint*/,
- const VPoint& /*nextPoint*/,
- Boolean /*mouseDidMove*/,
- Boolean /*turnItOn*/)
- {
- // Overridden to avoid standard feedback.
- } // TIconDrawCommand::TrackFeedback
-
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::TrackMouse:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- TTracker* TIconDrawCommand::TrackMouse(TrackPhase aTrackPhase,
- VPoint& /*anchorPoint*/,
- VPoint& previousPoint,
- VPoint& nextPoint,
- Boolean mouseDidMove)
- {
- VPoint fromBit;
- VPoint toBit;
- VPoint iconBit;
- short lineLength;
- float deltaH;
- float deltaV;
- float h;
- float v;
-
- // Convert nextPoint and previousPoint to bit locations in the icon…
- fIconEditView->PointToBit(fIconEditView->ViewToQDPt(nextPoint), toBit);
- fIconEditView->PointToBit(fIconEditView->ViewToQDPt(previousPoint), fromBit);
-
- if (aTrackPhase == trackBegin) // first time through
- {
- fTurnBitsOn =!fIconBitMap->GetBit(toBit); // Turn bits on or off?
- fOriginalIcon = fIconBitMap->Copy(); // Make a copy of the original for undo
- }
-
- if (mouseDidMove) // If mouse moved since last time…
- {
- // The following sets bits in the icon from the bit at previousPoint to the bit
- // at nextPoint. It is based on a simple line-drawing algorithm.
-
- lineLength = (short) Max(labs(toBit.h - fromBit.h), labs(toBit.v - fromBit.v));
- lineLength = (short) Max(1,lineLength); // This is on two lines so that Max can be "inlined"
-
- deltaH = (toBit.h - fromBit.h) / lineLength;
- deltaV = (toBit.v - fromBit.v) / lineLength;
-
- h = fromBit.h + 0.5;
- v = fromBit.v + 0.5;
-
- for (short i = 0; i < lineLength; i++)
- {
- iconBit.h = h;
- iconBit.v = v;
-
- fIconBitMap->SetBit(iconBit, fTurnBitsOn);// Set the bit in the icon
- fIconEditView->DrawBit(iconBit, fTurnBitsOn, fColor);// …and draw it in the edit view.
-
- // set the bit in the bitMapView model. this model will be used to generate
- // a setpoints apple event for recordability.
- fIconBitMapModel->SetBit(iconBit, TRUE);
-
- h = h + deltaH;
- v = v + deltaV;
- }
- }
-
- if (aTrackPhase == trackEnd) // when tracking is done, post a
- { // recordable apple event
- TDrawPointsAppleEvent *aDrawEvent = new TDrawPointsAppleEvent;
- aDrawEvent->IDrawPointsAppleEvent(fIconDocument, fIconBitMapModel, fTurnBitsOn);
- aDrawEvent->Send();
- }
- return this; // Return same command object.
- } // TIconDrawCommand::TrackMouse
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDrawCommand::DoIt()
- {
- VRect editViewExtent;
-
- fIconDocument->SetIcon(fIconBitMap); // Set the document's bit map
-
- // SetIcon invalidates all views of the document, including the one we just drew in.
- // To avoid flashing, validate the edit view here so it doesn't get redrawn.
-
- fIconEditView->GetExtent(editViewExtent);
- fIconEditView->ValidateVRect(editViewExtent);
- } // TIconDrawCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDrawCommand::UndoIt()
- {
- // Save a local copy of the current bit map, and reset it after the call to
- // SetIcon. This is necessary since SetIcon frees the current bitmap
- TIconBitMap* tempBitMap = fIconBitMap->Copy();
- fIconDocument->SetIcon(fOriginalIcon); // Restore icon to original state.
- fIconBitMap = tempBitMap;
- } // TIconDrawCommand::UndoIt
-
- //----------------------------------------------------------------------------------------
- // TIconDrawCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconDrawCommand::RedoIt()
- {
- // save a local copy of the current bit map, and reset it after the call to
- // SetIcon. This is necessary since SetIcon frees the current bitmap
- TIconBitMap* tempBitMap = fOriginalIcon->Copy();
- fIconDocument->SetIcon(fIconBitMap); // Set the icon back to the new one.
- fOriginalIcon = tempBitMap;
- } // TIconDrawCommand::RedoIt
-
-
- //========================================================================================
- // CLASS TIconEditCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TIconEditCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconEditCommand::Initialize:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TIconEditCommand::TIconEditCommand()
- {
- fIconDocument = NULL;
- fIconEditView = NULL;
- fSavedBitMap = NULL;
- } // TIconEditCommand::TIconEditCommand
-
- //----------------------------------------------------------------------------------------
- // TIconEditCommand::IIconEditCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconEditCommand::IIconEditCommand (CommandNumber itsCommandNumber,
- TIconEditView* itsIconEditView,
- TIconDocument* itsIconDocument)
-
- {
- this->ICommand( itsCommandNumber, // Initialize the command…
- itsIconDocument, // Associate it with a document.
- kCanUndo,
- kCausesChange,
- itsIconDocument);
-
- fChangesClipboard = (itsCommandNumber != cClear); // Cut or Copy changes the clipboard.
- fCausesChange = (itsCommandNumber != cCopy); // Cut or Clear changes the documnt.
-
- fIconEditView = itsIconEditView; // Remember reference to the view.
- fIconDocument = itsIconDocument; // Remember reference to the document.
- fSavedBitMap = fIconDocument->ReturnBitMap()->Copy();// Save a copy of the current bitmap.
- } // TIconEditCommand::IIconEditCommand
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- TIconEditCommand::~TIconEditCommand()
- {
- fSavedBitMap = (TIconBitMap*)FreeIfObject(fSavedBitMap); // Free the saved bitMap
- } // TIconEditCommand::Free
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconEditCommand::DoIt()
- {
- if (fIdentifier != cClear) // If the command is Cut or Copy…
- {
- TIconDocument* clipDocument;
- TIconEditView* clipView;
-
- // …copy the data to the clipboard.
-
- // Need a document to represent the data to be put on the clipboard.
- // If IIconDocument fails, it should free itself
- clipDocument = new TIconDocument;
- clipDocument->IIconDocument(NULL);
-
- // If IIconEditView fails it should free itself, but we need to free the document
- FailInfo fi;
- Try(fi)
- {
- clipView = new TIconEditView;
- clipView->IIconEditView(clipDocument, NULL, gZeroVPt, fIconEditView->GetMagnification());
-
- fSavedBitMap->CopyDataTo(clipDocument->ReturnBitMap());// Copy data to document icon.
-
- fi.Success(); // Don't need failure handler anymore.
- }
- else // Recover
- {
- clipDocument = (TIconDocument*)FreeIfObject(clipDocument);// Free clipDocument if non-NULL.
- fi.ReSignal();
- }
-
- // Tell the app we have a new clipboard.
- this->ClaimClipboard(clipView);
- }
-
- if (fIdentifier != cCopy) // Cut or Clear commands clear the icon.
- fIconDocument->ClearIcon(); // Clear the icon.
-
- } // TIconEditCommand::DoIt
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconEditCommand::RedoIt()
- {
- if (fIdentifier != cCopy) // Cut or Clear commands clear the icon.
- fIconDocument->ClearIcon();
- } // TIconEditCommand::RedoIt
-
-
- //----------------------------------------------------------------------------------------
- // TIconEditCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconEditCommand::UndoIt()
- { // If the command was Cut or Clear, the new
- if (fIdentifier != cCopy) // …icon was cleared, so restore it.
- {
- fSavedBitMap->CopyDataTo(fIconDocument->ReturnBitMap());
- fIconDocument->RedrawViews(); // Make sure all views get redrawn.
- }
- } // TIconEditCommand::UndoIt
-
- //========================================================================================
- // CLASS TIconPasteCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TIconPasteCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconPasteCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TIconPasteCommand::TIconPasteCommand()
- {
- fIconDocument = NULL;
- fIconEditView = NULL;
- fSavedIcon = NULL;
- } // TIconPasteCommand::TIconPasteCommand
-
- //----------------------------------------------------------------------------------------
- // TIconPasteCommand::IIconPasteCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TIconPasteCommand::IIconPasteCommand( TIconEditView* itsIconEditView,
- TIconDocument* itsIconDocument)
- {
- this->ICommand(cPaste, // Initialize the command…
- itsIconDocument, // Associate it with a document.
- kCanUndo,
- kCausesChange,
- itsIconDocument);
-
- fIconEditView = itsIconEditView; // Remember reference to the view.
- fIconDocument = itsIconDocument; // Remember reference to the document.
-
- TIconDocument* clipDoc = (TIconDocument*)gClipboardMgr->fClipView->fDocument;
- fSavedIcon = clipDoc->ReturnBitMap()->Copy();
- } // TIconPasteCommand::IIconPasteCommand
-
- //----------------------------------------------------------------------------------------
- // TIconPasteCommand::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- TIconPasteCommand::~TIconPasteCommand()
- {
- fSavedIcon = (TIconBitMap*)FreeIfObject(fSavedIcon);
- } // TIconPasteCommand::Free
-
- //----------------------------------------------------------------------------------------
- // TIconPasteCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconPasteCommand::DoIt()
- {
- TIconBitMap* tempIcon = fIconDocument->ReturnBitMap()->Copy();
- fIconDocument->SetIcon(fSavedIcon);
- fSavedIcon = tempIcon;
- } // TIconPasteCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TIconPasteCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TIconPasteCommand::UndoIt()
- {
- this->DoIt();
- } // TIconPasteCommand::UndoIt
-
- //========================================================================================
- // CLASS TIconBitMap
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TIconBitMap, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TIconBitMap::TIconBitMap()
- {
- fDataHandle = NULL;
- } // TIconBitMap::TIconBitMap
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::IIconBitMap:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::IIconBitMap()
- {
- this->IObject();
-
- FailInfo fi;
- Try(fi)
- {
- fDataHandle = NewPermHandle(kIconSizeInBytes); // Allocate a handle for the
- // bitmap.
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TIconBitMap::IIconBitMap
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TIconBitMap::~TIconBitMap()
- {
- fDataHandle = DisposeIfHandle(fDataHandle); // dispose of icon data.
- } // TIconBitMap::Free
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::SetIconBitMap:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::SetIconBitMap(Handle theBitMap)
- {
- MABlockMove(*theBitMap,
- *fDataHandle, // …then copy it into the document's
- kIconSizeInBytes); // …icon bitmap.
- } // TIconBitMap::SetIconBitMap
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::ReadFrom:
- //----------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- void TIconBitMap::ReadFrom(TStream* aStream)
- {
- long numberOfBytes;
-
- numberOfBytes = kIconSizeInBytes;
- aStream->ReadBytes(*fDataHandle, numberOfBytes);
- } // TIconBitMap::ReadFrom
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::WriteTo:
- //----------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- void TIconBitMap::WriteTo(TStream* aStream)
- {
- long numberOfBytes;
-
- numberOfBytes = kIconSizeInBytes;
- aStream->WriteBytes(*fDataHandle, numberOfBytes);
- } // TIconBitMap::WriteTo
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::LoadFromScrap:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TIconBitMap::LoadFromScrap()
- {
- long offset;
- long err;
-
- err = GetScrap(fDataHandle, kIconClipType, &offset); // Load the icon's data from the
- if (err < 0)
- FailOSErr((short) err); // the clip board and handle errors.
- } // TIconBitMap::LoadFromScrap
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::WriteToScrap:
- //----------------------------------------------------------------------------------------
- #pragma segment AClipboard
-
- void TIconBitMap::WriteToScrap()
- {
- FailOSErr(gClipboardMgr->PutDeskScrapData(kIconClipType, // Write the handle to the desk scrap, //new
- fDataHandle)); // …failing if an error occurs.
- } // TIconBitMap::WriteToScrap
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::Copy:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TIconBitMap* TIconBitMap::Copy()
- {
- TIconBitMap* copyOfIcon;
-
- copyOfIcon = new TIconBitMap; // Create a TIconBitMap object.
- copyOfIcon->IIconBitMap(); // Initialize it.
- copyOfIcon->SetIconBitMap(fDataHandle); // Copy the data.
- return copyOfIcon; // Return a reference to the new handle.
- } // TIconBitMap::Copy
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::CopyDataTo:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::CopyDataTo(TIconBitMap* anIcon)
- {
- anIcon->SetIconBitMap(fDataHandle); // Copy data to the new icon.
- } // TIconBitMap::CopyDataTo
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::Clear:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::Clear()
- {
- long* longPtr;
-
- longPtr = (long*) * fDataHandle;
- for (short i = 0; i < kIconSizeInLongs; i++)
- *longPtr++ = 0;
- } // TIconBitMap::Clear
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::Invert:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::Invert()
- {
- long* longPtr;
-
- longPtr = (long*) * fDataHandle;
- for (short i = 0; i < kIconSizeInLongs; i++)
- {
- *longPtr =~*longPtr;
- longPtr++;
- }
- } // TIconBitMap::Invert
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::Draw( const CRect& area,
- const CRGBColor& drawingColor)
- {
- CRGBColor saveColor;
-
- GetIfColor(saveColor);
- SetIfColor(drawingColor);
- PenNormal();
- PlotIcon(area, fDataHandle);
- SetIfColor(saveColor);
- } // TIconBitMap::Draw
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::GetBit:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- Boolean TIconBitMap::GetBit(VPoint iconBit)
- // Returns the state of the given bit in the icon being drawn.
- {
- short byte;
- short bitInByte;
-
- this->IconBitToByteBit(iconBit, byte, bitInByte);
-
- return (*(*fDataHandle + byte) >> bitInByte) & 1;
- } // TIconBitMap::GetBit
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::SetBit: Set the state of the given bit in the icon being drawn.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::SetBit(VPoint iconBit,
- Boolean turnBitOn)
- {
- short byte;
- short bitInByte;
- char theMask;
-
- this->IconBitToByteBit(iconBit, byte, bitInByte);
-
- theMask = (1 << bitInByte);
-
- if (turnBitOn)
- *(*fDataHandle + byte) |= theMask;
- else
- *(*fDataHandle + byte) &= ~theMask; // AND the complement of the mask.
- } // TIconBitMap::SetBit
-
-
- //----------------------------------------------------------------------------------------
- // TIconBitMap::IconBitToByteBit: This converts the given icon bit to a byte and bit in an
- // array of long words.
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TIconBitMap::IconBitToByteBit(VPoint iconBit, short& byte, short& bit)
- {
- long bitNumber;
-
- bitNumber = iconBit.v * kIconVBits + iconBit.h;
- byte = (short) bitNumber / 8;
- bit = (short) (7 - (bitNumber % 8));
- } // TIconBitMap::IconBitToByteBit
-
-
- //========================================================================================
- // CLASS TZoomOutCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TZoomOutCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TZoomOutCommand::TZoomOutCommand()
- {
- fIconDocument = NULL;
- } // TZoomOutCommand::TZoomOutCommand()
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TZoomOutCommand::~TZoomOutCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand::IZoomOutCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TZoomOutCommand::IZoomOutCommand(TIconDocument* itsIconDocument)
- {
- fIconDocument = itsIconDocument; // Save a reference to the icon document.
-
- this->ICommand(cZoomOut, // Initialize the inherited data…
- itsIconDocument,
- kCanUndo,
- kCausesChange,
- itsIconDocument); // …no view or scroller to track.
- } //TZoomOutCommand::IZoomOutCommand
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand::MakeAppleEvent()
- //----------------------------------------------------------------------------------------
- TAppleEvent * TZoomOutCommand::MakeAppleEvent()
- {
- CTempDesc directObjectDesc;
- TAppleEvent * theZoomOutAppleEvent = new TAppleEvent;
-
- theZoomOutAppleEvent->IAppleEvent(kAEIconEditClass, kAEZoomOutID,gServerAddress, kAENoReply);
- fIconDocument->MakeObjectSpecifier(directObjectDesc, fIconDocument->GetSpecifierForm());
- theZoomOutAppleEvent->WriteParameter(keyDirectObject, directObjectDesc);
-
- return theZoomOutAppleEvent;
- } //TZoomOutCommand::MakeAppleEvent
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TZoomOutCommand::DoIt()
- {
- short currentMagnification = fIconDocument->GetIconView()->GetMagnification();
- fIconDocument->GetIconView()->SetMagnification(currentMagnification - 2);
- } // TZoomOutCommand::DoIt
-
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TZoomOutCommand::UndoIt()
- {
- short currentMagnification = fIconDocument->GetIconView()->GetMagnification();
- fIconDocument->GetIconView()->SetMagnification(currentMagnification + 2);
- } // TZoomOutCommand::UndoIt
-
-
- //----------------------------------------------------------------------------------------
- // TZoomOutCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TZoomOutCommand::RedoIt()
- {
- short currentMagnification = fIconDocument->GetIconView()->GetMagnification();
- fIconDocument->GetIconView()->SetMagnification(currentMagnification - 2);
- } // TZoomOutCommand::RedoIt
-
- //========================================================================================
- // CLASS TZoomInCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment ASelCommand
- MA_DEFINE_CLASS_M1(TZoomInCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- TZoomInCommand::TZoomInCommand()
- {
- fIconDocument = NULL;
- } // TZoomInCommand::TZoomInCommand()
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TZoomInCommand::~TZoomInCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand::IZoomInCommand
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TZoomInCommand::IZoomInCommand(TIconDocument* itsIconDocument)
- {
- fIconDocument = itsIconDocument; // Save a reference to the icon document.
-
- this->ICommand(cZoomIn, // Initialize the inherited data…
- itsIconDocument,
- kCanUndo,
- kCausesChange,
- itsIconDocument); // …no view or scroller to track.
- } //TZoomInCommand::IZoomInCommand
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand::MakeAppleEvent()
- //----------------------------------------------------------------------------------------
- TAppleEvent * TZoomInCommand::MakeAppleEvent()
- {
- CTempDesc directObjectDesc;
- TAppleEvent * theZoomInAppleEvent = new TAppleEvent;
-
- theZoomInAppleEvent->IAppleEvent(kAEIconEditClass, kAEZoomInID,gServerAddress, kAENoReply);
- fIconDocument->MakeObjectSpecifier(directObjectDesc, fIconDocument->GetSpecifierForm());
- theZoomInAppleEvent->WriteParameter(keyDirectObject, directObjectDesc);
-
- return theZoomInAppleEvent;
- } //TZoomInCommand::MakeAppleEvent
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TZoomInCommand::DoIt()
- {
- short currentMagnification = fIconDocument->GetIconView()->GetMagnification();
- fIconDocument->GetIconView()->SetMagnification(currentMagnification + 2);
- } // TZoomInCommand::DoIt
-
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand::UndoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TZoomInCommand::UndoIt()
- {
- short currentMagnification = fIconDocument->GetIconView()->GetMagnification();
- fIconDocument->GetIconView()->SetMagnification(currentMagnification - 2);
- } // TZoomInCommand::UndoIt
-
-
- //----------------------------------------------------------------------------------------
- // TZoomInCommand::RedoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- void TZoomInCommand::RedoIt()
- {
- short currentMagnification = fIconDocument->GetIconView()->GetMagnification();
- fIconDocument->GetIconView()->SetMagnification(currentMagnification + 2);
- } // TZoomInCommand::RedoIt
-
- //----------------------------------------------------------------------------------------
- // End of UIconEdit.cp
-
- #pragma segment Inline
-